use std::ops::Add;

/// 声明宏
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        start();
    }
}

macro_rules! unless {
    ($arg:expr, $branch:expr) => {
        if $arg {
            $branch
        };
    };
}

pub fn start() {
    let a = 5;
    let b = 3;
    unless!(a > b, { println!("a > b") });

    let first = Complex::new(1, 2);
    let second: Complex<i32> = Complex::default();
    println!("{:?}", second + first);
    println!("{:?}", first);

    let str_comp = Complex::new("12".to_owned(), "32".to_owned());
    let str_comp_2 = str_comp;
    println!("{:?}", str_comp_2);
}

#[derive(Debug, Copy, Clone, Default)]
struct Complex<T> {
    re: T, // 实部
    im: T, // 虚部
}

impl<T> Complex<T> {
    pub fn new(re: T, im: T) -> Self {
        Self { re, im }
    }
}

impl<T> From<(T, T)> for Complex<T> {
    fn from(value: (T, T)) -> Self {
        Self::new(value.0, value.1)
    }
}

impl<T: Add<T, Output = T>> Add for Complex<T> {
    type Output = Complex<T>;

    fn add(self, rhs: Self) -> Self::Output {
        Complex::new(self.re + rhs.re, self.im + rhs.im)
    }
}

#[derive(Debug)]
struct Foo;
